// state
const state = {
  inquiries: [],
  currentInquiry: null
}

// getters
const getters = {
  getInquiries: (state) => state.inquiries,
  getCurrentInquiry: (state) => state.currentInquiry
}

// mutations
const mutations = {
  SET_INQUIRIES(state, inquiries) { state.inquiries = inquiries },
  SET_CURRENT_INQUIRY(state, detail) { state.currentInquiry = detail }
}

// actions
const actions = {
  // 获取统计数据
  async getStatistics(_, params) {
    // 模拟统计数据
    return {
      trendData: [120, 200, 150, 80, 70, 110, 130],
      replyRateData: [
        { value: 1048, name: '已回复' },
        { value: 735, name: '未回复' }
      ],
      questionTypeData: [
        { value: 1048, name: '技术问题' },
        { value: 735, name: '商务问题' },
        { value: 580, name: '资质问题' },
        { value: 484, name: '其他问题' }
      ],
      responseTimeData: [120, 200, 150, 80, 70, 110]
    }
  },

  // 获取询标列表
  async getInquiryList({ commit }) {
    // 模拟询标列表数据
    const data = [
      {
        id: 1,
        projectId: 'P001',
        projectName: '示例项目1',
        content: '这是一个示例询标内容',
        status: 'pending',
        createTime: '2024-03-20 10:00:00'
      },
      {
        id: 2,
        projectId: 'P002',
        projectName: '示例项目2',
        content: '这是另一个示例询标内容',
        status: 'replied',
        createTime: '2024-03-19 15:30:00'
      }
    ]
    commit('SET_INQUIRIES', data)
    return data
  },

  // 获取询标详情
  async getInquiryDetail({ commit }, id) {
    // 模拟询标详情数据
    const detail = {
      id,
      projectId: 'P001',
      projectName: '示例项目',
      content: '这是一个示例询标内容',
      status: 'pending',
      createTime: '2024-03-20 10:00:00',
      files: [
        {
          name: '示例文件1.pdf',
          size: 1024 * 1024,
          url: '#'
        }
      ],
      replies: [
        {
          content: '这是一个示例回复',
          replyTime: '2024-03-20 11:00:00',
          files: []
        }
      ]
    }
    commit('SET_CURRENT_INQUIRY', detail)
    return detail
  }
}

export default { namespaced: true, state, getters, mutations, actions }
